﻿using System;

namespace Safebrowsing
{
    /// <summary>
    /// Represents Google Safe Browsing API exception.
    /// Exception type depends on HTTP response code.
    /// </summary>
    public class SafebrowsingApiException : ApplicationException
    {
        internal SafebrowsingApiException(string message, Exception innerException, SafebrowsingErrorCode errorCode)
            : base(message, innerException)
        {
            ErrorCode = errorCode;
        }

        internal SafebrowsingApiException(string message, SafebrowsingErrorCode errorCode)
            : this(message, null, errorCode)
        {
        }

        internal SafebrowsingApiException(string message, Exception innerException)
            : this(message, innerException, SafebrowsingErrorCode.Unknown)
        {
        }

        internal SafebrowsingApiException(string message) : this(message, null, SafebrowsingErrorCode.Unknown)
        {
        }

        public SafebrowsingErrorCode ErrorCode { get; private set; }
    }

    public enum SafebrowsingErrorCode
    {
        /// <summary>
        /// Unknown exception
        /// </summary>
        Unknown,

        /// <summary>
        /// 400: Bad Request — The HTTP request was not correctly formed. The client did not provide all required CGI parameters.
        /// </summary>
        BadRequest,

        /// <summary>
        /// 401: Not Authorized — The client id is invalid.
        /// </summary>
        NotAuthorized,

        /// <summary>
        /// 403: Forbidden — The client id is invalid.
        /// </summary>
        Forbidden,

        /// <summary>
        /// 503: Service Unavailable — The server cannot handle the request. Clients MUST follow the backoff behavior specified in the Request Frequency section.
        /// </summary>
        ServiceUnavailable,

        /// <summary>
        /// 505: HTTP Version Not Supported — The server CANNOT handle the requested protocol major version.
        /// </summary>
        HttpVersionNotSupported
    }
}